package main

import (
	"fmt"
	"io"
	"net"
	"os"
)

type echo struct {
	w io.Writer
}

func (c echo)Write(p []byte) (n int, err error) {
	c.w.Write([]byte("you say: "))
	n, err = c.w.Write(p)
	c.w.Write([]byte("\n"))
	return
}

func main() {
	l, err := net.Listen("tcp", "localhost:29000")
	if err != nil {
		fmt.Println("net Listen: ", err)
		os.Exit(-1)
	}

	for {
		conn, err := l.Accept()
		if err != nil {
			fmt.Println("listen err: ", err)
			break
		}
		go func (c net.Conn) {
			io.Copy(echo{conn}, conn)
		}(conn)
	}
}